var status = -1;

function action(e, c, b) {
    if (e == 1) {
        status++
    } else {
        if (status == 0) {
            cm.dispose()
        }
        status--
    }
    if (status == 0) {
        if (cm.getPlayer().getMapId() == 863010600) {
            cm.askYesNo("哇哇哇!!!你既然成功平息了贝勒德的愤怒,请让我为勇士颁发奖励吧!!!")
        } else {
            cm.sendOk("哼！旁边的老头抢了我的货物，我非常气愤。");
            cm.dispose()
        }
    } else {
        if (status == 1) {
            if ((cm.getSpace(1) > 1 || cm.getSpace(2) > 1 || cm.getSpace(3) > 1 || cm.getSpace(4) > 1)) {
                var d;
                var f = Math.floor(Math.random() * 500);
                if (f >= 0 && f <= 440) {
                    var a = new Array(1113072, 1032220, 1122264, 1132243);
                    d = cm.gainGachaponItem(a[Math.floor(Math.random() * a.length)], 1, "贝勒德", 3)
                } else {
                    if (f >= 441 && f <= 470) {
                        var a = new Array(1113073, 1032221, 1122265, 1132244);
                        d = cm.gainGachaponItem(a[Math.floor(Math.random() * a.length)], 1, "贝勒德", 3)
                    } else {
                        if (f >= 471 && f <= 490) {
                            var a = new Array(1113074, 1032222, 1122266, 1132245);
                            d = cm.gainGachaponItem(a[Math.floor(Math.random() * a.length)], 1, "贝勒德", 3)
                        } else {
                            var a = new Array(1113075, 1032223, 1122267, 1132246);
                            d = cm.gainGachaponItem(a[Math.floor(Math.random() * a.length)], 1, "贝勒德", 3)
                        }
                    }
                }
                if (d != -1) {
                    cm.warp(863000100);
                    cm.dispose()
                } else {
                    cm.sendOk("请你确认在背包的装备,消耗,其他窗口中是否有一格以上的空间?")
                }
            } else {
                cm.sendOk("xx错误")
            }
            cm.dispose()
        }
    }
}

function start() {
    status = -1;
    action(1, 0, 0)
};